package com.dc.project.controller;

import com.dc.common.validated.InsertGroup;
import com.dc.common.validated.QueryGroup;
import com.dc.common.validated.UpdateGroup;
import com.dc.common.vo.ResultVo;
import com.dc.project.workflow.dto.WfCategoryDto;
import com.dc.project.workflow.entity.WfCategory;
import com.dc.project.workflow.entity.WfModelCategory;
import com.dc.project.workflow.service.WfCategoryService;
import com.dc.project.workflow.service.WfModelCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;

/**
 * 流程分类表(WfModelCategory)表控制层
 *
 * @author zhuangcy
 * @since 2021-06-21 15:50:27
 */
@RestController
@RequestMapping("wfCategory")
@Api(tags = "流程分类表")
public class WfCategoryController {
    /**
     * 服务对象
     */
    @Autowired
    private WfCategoryService wfCategoryService;
    @Autowired
    private WfModelCategoryService wfModelCategoryService;

    /**
     * 查询流程分类表列表
     *
     * @param dto
     * @return
     */
    @GetMapping
    @ApiOperation("查询流程分类表列表")
    @RequiresPermissions(value = {"flow:wfCategory:query", "flow:todoTask:query", "flow:historyTask:query"}, logical = Logical.OR)
    public ResultVo list(@Validated(QueryGroup.class) WfCategoryDto dto) {
        return this.wfCategoryService.queryByList(dto);
    }

    /**
     * 新增流程分类表
     *
     * @param wfCategory
     * @return
     */
    @PostMapping
    @ApiOperation("新增流程分类表")
    @RequiresPermissions("flow:wfCategory:add")
    public ResultVo add(@Validated(value = {InsertGroup.class}) @RequestBody WfCategory wfCategory) {
        return this.wfCategoryService.add(wfCategory);
    }

    /**
     * 编辑流程分类表
     *
     * @param wfCategory
     * @return
     */
    @PutMapping
    @ApiOperation("编辑流程分类表")
    @RequiresPermissions("flow:wfCategory:edit")
    public ResultVo edit(@Validated(value = {UpdateGroup.class}) @RequestBody WfCategory wfCategory) {
        return this.wfCategoryService.edit(wfCategory);
    }

    /**
     * 根据主键删除流程分类表
     *
     * @param id 主键
     * @return
     */
    @DeleteMapping("{id}")
    @ApiOperation("根据主键删除流程分类表")
    @RequiresPermissions("flow:wfCategory:delete")
    public ResultVo delete(@PathVariable Serializable id) {
        return this.wfCategoryService.delete(id);
    }


    /**
     * 查询流程分类关联信息
     *
     * @param dto
     * @return
     */
    @GetMapping("modelCategory")
    @ApiOperation("查询流程分类关联信息")
    @RequiresPermissions(value = {"flow:wfCategory:query"}, logical = Logical.OR)
    public ResultVo getModelCategory(@Validated(QueryGroup.class) WfCategoryDto dto) {
        return this.wfCategoryService.getModelCategory(dto);
    }


    /**
     * 新增流程分类
     *
     * @param wfCategory
     * @return
     */
    @PostMapping("model")
    @ApiOperation("新增流程分类")
    @RequiresPermissions(value = {"flow:wfCategory:add"}, logical = Logical.OR)
    public ResultVo addModelCategory(@Validated(value = {InsertGroup.class}) @RequestBody WfModelCategory wfCategory) {
        return this.wfModelCategoryService.add(wfCategory);
    }

    /**
     * 编辑流程分类
     *
     * @param wfCategory
     * @return
     */
    @PutMapping("model")
    @ApiOperation("编辑流程分类")
    @RequiresPermissions(value = {"flow:wfCategory:add"}, logical = Logical.OR)
    public ResultVo editModelCategory(@Validated(value = {UpdateGroup.class}) @RequestBody WfModelCategory wfCategory) {
        return this.wfModelCategoryService.edit(wfCategory);
    }


}